const highlight = require("./libs/highlight.js")
const lineNumbers = require("./libs/lineNumbers.js")
const preWrapper  = require("./libs/preWrapper.js")
const hlRawcode = require("./libs/hlRawCode.js")
var md= require("markdown-it")({
    html:true,
    linkify:true,
    typographer:true,
    highlight:highlight

})


//var cjk_breaks = require('markdown-it-cjk-breaks');
var mdSmartArrows = require('markdown-it-smartarrows');
var imsize = require('markdown-it-imsize')
var mk = require('markdown-it-katex-external')

md.use(mdSmartArrows)
    .use(preWrapper)
    .use(lineNumbers)
    .use(imsize)
    .use(mk, {"throwOnError" : false, "errorColor" : " #cc0000"})
    .use(require('markdown-it-task-lists'))
    .use(require('markdown-it-sub'))
    .use(require('markdown-it-sup'))
    .use(require('markdown-it-multimd-table'), {enableMultilineRows: true})
    .use(require("markdown-it-anchor"),{
        level: 2,
        slugify: function(string){  return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)},
    })
    .use(require("markdown-it-table-of-contents"))
    .use( require('markdown-it-emoji'))
    .use(require('markdown-it-footnote'))

/* 需要在前端引用 twemoji.js */
/*
 *md.renderer.rules.emoji = function(token, idx) {
 *    return twemoji.parse(token[idx].content);
 *};
 *
 *var window = window || undefined
 *
 *[> 这个部分: 在前端要手动加入 <]
 *if( window !== undefined)
 *    window.abbc = require("./copy_plugin.js")
 */

module.exports = md

window.hlRawcode = hlRawcode
window.CLIPBOARD = require("./libs/copyPlugin.js")


